#更新员工信息
import sys
sys.path.append("..")
import json
from flask import request
from db_client import *

def update_staff():
    #更新员工信息
    token = request.headers.get('token')
    flag, right = token_client.check_token(token)
    if not flag:
        t = {
            'state': 'false',
            'msg': '更新失败'
        }
        return json.dumps(t, ensure_ascii=False)
    else:
        data = json.loads(request.get_data())
        _id = data['id']
        name = data['name']
        s_id = data['superior_id']
        job = data['job']
        dept = data['department']
        passwd = data['password']
        
        flag2 = mysql_client.update_staff(_id, name, s_id, job, dept, passwd)
        if flag2:
            t = {
                'state': 'true',
                'msg': 'success'
            }
            return json.dumps(t, ensure_ascii=False)
        else:
            t = {
                'state': 'flase',
                'msg': '更新失败'
            }
            return json.dumps(t, ensure_ascii=False)